<?php
//响应APP端
//function json_Response($code,$message,$data = NULL,$type=3)
//{
//    //清空缓冲区内容
//    ob_end_clean();
//    //设置json响应头
//    header("Content-type: application/json");
//    if($type==1){
//        echo json_encode($data,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
//        exit();
//    }elseif($type==2){
//        echo json_encode(array('statecode'=>$code,'statemessage'=>$message),JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
//        exit();
//    }elseif ($type==3){
////        echo json_encode(array('statecode'=>$code,'statemessage'=>$message,$data),JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
//          $data['statecode']=$code;
//          $data['statemessage']=$message;
//        echo json_encode($data,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
//        exit();
//        }
//}


function json_Response($code,$message,$data = NULL,$type=3)
{
    //清空缓冲区内容
    ob_end_clean();
    //设置json响应头
//    header("Content-type: application/json");
    if($type==1){
        echo json_encode($data,JSON_UNESCAPED_SLASHES);
        exit();
    }elseif($type==2){
        echo json_encode(array('statecode'=>$code,'statemessage'=>$message),JSON_UNESCAPED_SLASHES);
        exit();
    }elseif ($type==3){
//        echo json_encode(array('statecode'=>$code,'statemessage'=>$message,$data),JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
        $data['statecode']=$code;
        $data['statemessage']=$message;
        echo json_encode($data,JSON_UNESCAPED_SLASHES);
        exit();
    }
}

function get_attr($a,$pid){
    $tree = array();
    foreach($a as $v){
        if($v['pid'] == $pid){
            $v['children'] = get_attr($a,$v['id']);
            if($v['children'] == null){
                unset($v['children']);
            }
            $tree[] = $v;
        }
    }
    return $tree;
}


